<?php
/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 14-10-13
 * Time: 下午2:08
 */

class SiteController extends BaseController{

    public function index(){
        $user = PubAuth::getUser();
        if(!empty($user)){
            $this->redirect('/home/?r=site/game');
        }
    }

    public function game(){
        $gameList = PubAuth::getMyGameList();
        if(count($gameList) == 1){
            $currentGame = current($gameList);
            $this->redirect('/data/?g='.$currentGame['GameSrc']);
        }

        $this->out['game'] = $gameList;
        $this->out['platform'] = PubAuth::getMyPlatformList();
    }

    public function go(){
        $gameId = $this->R('game');

        $result = AuthService::init($gameId);
        if($result){
            $this->redirect('/data/?r=index&game='.$gameId);
        }
    }

    public function login(){
        $user = $this->R('user');
        $password = $this->R('password');

        $this->outType = 'json';
        $this->out = AuthService::login($user, $password);
    }

    public function logout(){
        PubAuth::logout();
    }

} 
